package net.guerlab.credits.creditsoption.dqi.impl;

import org.apache.commons.lang3.StringUtils;

import net.guerlab.credits.creditsoption.dqi.CreditsOptionDQI;
import net.guerlab.credits.creditsoption.entity.CreditsOption;
import net.guerlab.credits.creditsoption.exception.CreditIdIsNullError;
import net.guerlab.credits.creditsoption.exception.CreditNameIsNullError;
import net.guerlab.credits.creditsoption.exception.CreditsOptionIsNullError;

/**
 * 积分设置数据查询接口简单实现类
 * 
 * @author guer
 *
 */
public class CreditsOptionDQIImpl extends CreditsOptionDQI {

    private static final long serialVersionUID = 1L;

    @Override
    public void saveCheck(CreditsOption entity) {
        if (entity == null) {
            throw new CreditsOptionIsNullError();
        }

        if (StringUtils.isBlank(entity.getCreditName())) {
            throw new CreditNameIsNullError();
        }
    }

    @Override
    public void updateCheck(CreditsOption entity) {
        if (entity == null) {
            throw new CreditsOptionIsNullError();
        }

        if (entity.getCreditId() == null || entity.getCreditId() <= 0) {
            throw new CreditIdIsNullError();
        }

        if (StringUtils.isBlank(entity.getCreditName())) {
            throw new CreditNameIsNullError();
        }
    }

    @Override
    public void deleteCheck(CreditsOption entity) {
        if (entity == null) {
            throw new CreditsOptionIsNullError();
        }

        if (entity.getCreditId() == null || entity.getCreditId() <= 0) {
            throw new CreditIdIsNullError();
        }
    }

}
